package com.example.a12502.aihome.history;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Spinner;

import com.example.a12502.aihome.R;

import java.util.ArrayList;
import java.util.List;

public class PmFragment extends Fragment {

    private Spinner spinner;
    private ImageView image1;
    private int draw1;
    private int draw2;
    private int draw3;
    private List<Integer> drawlist;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_history_pm, container, false);
        spinner = view.findViewById(R.id.spinner);
        image1 = view.findViewById(R.id.pmchart);
        initList(view);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                image1.setImageResource(drawlist.get(position));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                image1.setImageResource(drawlist.get(0));
            }
        });

        return view;
    }

    @SuppressLint("ResourceType")
    public void initList(View view){
        image1 = view.findViewById(R.id.pmchart);
        drawlist = new ArrayList<>();
        draw1 =  R.drawable.pm_1_drawable;
        draw2 =  R.drawable.pm_2_drawable;
        draw3 = R.drawable.pm_3_drawable;
        drawlist.add(draw1);
        drawlist.add(draw2);
        drawlist.add(draw3);
    }
}
